$(function () {
    initEvent();
    getUserInfo();
});

function initEvent() {
    $("#submitMsg").off('click').on('click', function () {
        submitMsg();
    });
}

// 获取居住地(城市联动)
function getCity(flag,id,objid){
    if(objid == 'icity' || objid == 'iarea' || objid == 'wcity' || objid == 'warea'){
        if('' == id){
            falert('请选择正确的省市区');
            return false;
        }
    }
    id = id || '';
    flag = flag || false;
    var datas = {
        interface:'users@getCity',    
    };
    if(flag && id){
        datas.id = id;
    }
    common.ajax({
        data: datas,
        unlock: 1,   
        success: function (data) {
            if (data.status == '2000') {
                if(flag == 'city'){
                    var html = '<option value="" val="">选择市</option>';
                    $('#'+objid).html(html);
                    if(objid == 'wcity'){
                        $('#warea').html('<option value="" val="">选择区</option>');
                    }else if(objid == 'icity'){
                        $('#iarea').html('<option value="" val="">选择区</option>');
                    }
                    html += common.formatTemplate(data.result,'<option value="{city_name}" val="{city_key}">{city_name}</option>',true);
                    $('#'+objid).html(html);
                }else if(flag == 'area'){
                    var html = '<option value="" val="">选择区</option>';
                    html += common.formatTemplate(data.result,'<option value="{city_name}" val="{city_key}">{city_name}</option>',true);  
                    $('#'+objid).html(html);
                }else{
                    var html = '<option value="" val="">选择省</option>';
                    html += common.formatTemplate(data.result,'<option value="{city_name}" val="{city_key}">{city_name}</option>',true);  
                    $('#'+objid).html(html);
                }
             
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });  
}

function getFldInfo(){
    var value = $('#parent').find("option:selected").text()+'->'+$('#child1').find("option:selected").text()+'->'+$('#child2').find("option:selected").text()+'->'+$('#child3').find("option:selected").text();
    $('#uw_fld').val($('#child3').find("option:selected").val());
    $('#uw_fld_name').val(value);
}

var list2 = {'I':['64','65'],'J':['66','69'],'K':['70','71'],'L':['72'],'M':['74'],'O':['79','81'],'P':['82']};
var list2_ = {'64':'互联网和相关服务','65':'软件和信息技术服务业','66':'货币金融服务','69':'其他金融业','70':'房地产业','71':'租赁业','72':'商务服务业','74':'专业技术服务业','79':'居民服务业','81':'其他服务业','82':'教育'};

// 第3级
var list3 = {'64':['642','649'],'65':['659','651'],'66':['663'],'69':['691','693'],'70':['703'],'71':['712'],'72':['723','727','729'],'74':['749'],'79':['791','799'],'81':['819'],'82':['829']};
var list3_ = {'642':'互联网信息服务','649':'其他互联网服务','651':'软件开发','659':'其他信息技术服务业','663':'非货币银行服务','691':'金融信托与管理服务','693':'非金融机构支付服务','703':'房地产中介服务','712':'文化及日用品出租','723':'咨询与调查','727':'旅行社及相关服务','729':'其他商务服务业','749':'其他专业技术服务业','791':'家庭服务','799':'其他居民服务业','819':'其他未列明服务业','829':'技能培训、教育辅助及其他教育'};

//第4级
var list4 = {'642':['6420'],'649':['6490'],'651':['6510'],'659':['6599'],'663':['6631','6633'],'691':['6910'],'693':['6930'],'703':['7030'],'712':['7129'],'723':['7239'],'727':['7279'],'729':['7299'],'749':['7491','7499'],'791':['7910'],'799':['7990'],'819':['8190'],'829':['8299']};
var list4_ = {'6420':'互联网信息服务','6490':'其他互联网服务','6510':'软件开发','6599':'其他未列明信息技术服务业','6631':'金融租赁服务','6633':'典当','6910':'金融信托与管理服务','6930':'非金融机构支付服务','7030':'房地产中介服务','7129':'其他文化及日用品出租','7239':'其他专业咨询','7279':'其他旅行社相关服务','7299':'其他未列明商务服务业','7491':'专业化设计服务','7499':'其他未列明专业技术服务业','7910':'家庭服务','7990':'其他居民服务业','8190':'其他未列明服务业','8299':'其他未列明教育'};

var default_ = '<option value="">请选择</option>';

function clickOpt(num){
    var html1=default_;
     $.each(list2[num],function(key,val){
        html1 += '<option value="'+val+'">'+list2_[val]+'</option>';
         $('#child1').html(html1);
      });
     $('#child2').html(default_);
     $('#child3').html(default_);
     $('#child4').html(default_);
   
}

function clickOpt1(num,v,list){
    var html2=default_;
     var arr = list3_;
     if(3==num){
       arr = list4_;
     }
     $.each(list,function(key3,val3){
        html2 += '<option value="'+val3+'">'+arr[val3]+'</option>';
         $('#child'+num).html(html2);
      });
   
}

// 提交影像信息
function pictureSave(type) {
    var flag = true;
    if(type == '1'){
        var arr = ['1', '2', '3'];
        var daturm = [];
        $.each(arr, function (i, o) {
            if($('#file' + o).val() == ''){
                flag = false;
                return false;
            }
            var file = [o, $('#file' + o).val()];
            daturm.push(file);
        });
    }else{
        var daturm = [];
        $.each($('.userfiles'), function (i, o) {
            if($(o).val() == ''){
                flag = false;
                return false;
            }
            var file = [$(o).attr('fileType'), $(o).val()];
            daturm.push(file);
        });
    }
    if(!flag){
        falert('请您上传资料');
        return false;
    }

    var datas = new Object;
    datas.daturmInfo = daturm;
    datas.b_id = common.get('id');
    datas.interface = 'users@userUpload';
    
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                if(type == '1'){
                    $('#msgSfzPeople').remove();
                    $(".banner1").css("min-height","8.75rem");
                }else{
                    $('#msgYxzlPeople').remove();
                }
                falert('保存成功');
                $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });  
    
}

// 提交个人信息
function msgPeople() {
    var datas = common.formatFormData('msgInfo');
    if(!checkParams(datas)) return false;
    
//    var email = $('#u_email').val();
//
//    var result = common.checkForm().checkEmail(email, function (result, error) {
//        if (result == false) {
//            falert(error);
//            return false;
//        }
//    }).value;
    
    if($("input[name='address']").val().length < 3){
        falert('请输入至少3位以上的详细地址');
        return false;
    }
    
//    if(result == true){
        datas.interface = 'users@douserInfo';      
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    getTplHtml('msg',$('#msgInfo'));
                    $(".banner3").css("min-height","8.45rem");
                    common.ajax({
                        data: {interface:'users@userInfo'},
                        success: function (data) {
                            if (data.status == '2000') {
                                setTimeout(function(){$('#msgInfo').html(common.formatTemplate(data.result,$('#msgInfo').html()));}, 500);
                            } else if (data.status == '5000') {
                                falert(data.msg);
                            }
                        }
                    });
                    falert('保存成功');
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
//    }
    
}

// 提交联系人信息
function contactMsg(){
    var contactInfo1 = common.formatFormData('contactInfo1');
    if(!checkParams(contactInfo1)) return false;
    var contactInfo2 = common.formatFormData('contactInfo2');
    if(!checkParams(contactInfo2)) return false;
    
    var relationArr = [];
    var phonearr = [];
    var flag = true;
    var nflag = true;
    for (var i = 1; i <= 2; i++) {
        var relation =  $("#relation"+i).val();
        var phone = $("#phone"+i).val();
        var name = $("#name" + i).val();
        common.checkForm().checkName(name, function (result, error) {
            if (result == false) {
                falert(error);
                nflag = false;
                return false;
            }else{
                nflag = true;
            }
        });
        common.checkForm().checkMobile(phone, function (result, error) {
            if (result == false) {
                falert(error);
                flag = false;
                return false;
            }else{
                flag = true;
            }
        });
        if(phone){
            phonearr.push(phone);
        }
        if(relation=='父亲' || relation=='母亲' || relation=='配偶'){
            relationArr.push(relation);
        }
    }
    if(!flag || !nflag){
        return false;
    }
    if(/(\x0f[^\x0f]+)\x0f[\s\S]*\1/.test("\x0f"+relationArr.join("\x0f\x0f") +"\x0f")){
        falert('两个紧急联系人不能重复');
        return false;
    }
    if(/(\x0f[^\x0f]+)\x0f[\s\S]*\1/.test("\x0f"+phonearr.join("\x0f\x0f") +"\x0f")){
        falert('手机号不能重复');
        return false;
    }
    var arr = [];
    arr.push(contactInfo1);
    arr.push(contactInfo2);
    var datas = new Object;
    datas.relations = arr;
    datas.interface = 'users@doContact'; 

    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                $('#contactMsg').remove();
                getTplHtml('contact1',$('#contactInfo1'));
                getTplHtml('contact2',$('#contactInfo2'));
                $(".banner5").css("min-height","10.8rem");
                common.ajax({
                    data: {interface:'users@contact'},
                    success: function (data) {
                        if (data.status == '2000') {
                            setTimeout(function(){
                                $('#contactInfo1').html(common.formatTemplate(data.result[0],$('#contactInfo1').html()));
                                $('#contactInfo2').html(common.formatTemplate(data.result[1],$('#contactInfo2').html()));
                            }, 500);
                        } else if (data.status == '5000') {
                            falert(data.msg);
                        }
                    }
                });
                falert('保存成功');
                $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}

// 提交工作信息
function workmsgSave() {
    var datas = common.formatFormData('workInfo');
    if(!checkParams(datas)) return false;
    
    var biaos = $('#biaos').val();
    var flag = true;
    if(biaos == '3'){
        if($("input[name='com_name']").val().length < 3){
            falert('请输入至少3位以上的学校名称');
            return false;
        }else if($("input[name='indiv_post']").val().length < 2){
            falert('请输入至少2位的专业名称');
            return false;
        }
        flag = common.checkForm().checkTime($('#school_date').val(), function (result, error) {
            if (result == false) {
                falert(error);
                return false;
            }
        }).value;
    }else{
        if($("input[name='com_name']").val().length < 3){
            falert('请输入至少3位以上的单位名称');
            return false;
        }else if($("input[name='com_addr']").val().length < 3){
            falert('请输入至少3位以上的单位地址');
            return false;
        }
    }
    
    if(flag == true){
        datas.interface = 'users@doworkInfo';     
        common.ajax({
            data: datas,
            success: function (data) {
                if (data.status == '2000') {
                    getTplHtml('work'+biaos,$('#workInfo'));
                    if(biaos == '1'){
                        $(".banner4").css("min-height","12.3rem");
                    }else if(biaos == '2'){
                        $(".banner4").css("min-height","7.2rem");
                    }else if(biaos == '3'){
                        $(".banner4").css("min-height","7.2rem");
                    }
                    common.ajax({
                        data: {interface:'users@workInfo'},
                        success: function (data) {
                            if (data.status == '2000') {
                                if(data.result.cus_flag == '1'){
                                    data.result.cus_flag = '自雇';
                                }else if(data.result.cus_flag == '2'){
                                    data.result.cus_flag = '在职';
                                }else if(data.result.cus_flag == '3'){
                                    data.result.cus_flag = '学生';
                                }
                                setTimeout(function(){$('#workInfo').html(common.formatTemplate(data.result,$('#workInfo').html()));}, 500);
                            } else if (data.status == '5000') {
                                falert(data.msg);
                            }
                        }
                    });
                    falert('保存成功');
                    $('#checkSubmit').val(parseInt($('#checkSubmit').val())+1);
                } else if (data.status == '5000') {
                    falert(data.msg);
                }
            }
        });
    }
}

function getUserInfo(){
    var datas = {
        interface:'users@backUserInfo',
        infoType: '1',
        b_id:common.get('id'),
    };
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                $('#name').val(data.result.userInfo.u_true_name);
                $('#code').val(data.result.userInfo.u_ident_no);
                $('#biaosTP').val(data.result.workInfo.cus_flag);
                if(data.result.orderInfo.back_type.indexOf('1') >= 0){
                    if(data.result.daturmInfo.length>0){
                        var imghtml = '';
                        var num = 1;
                        $.each(data.result.daturmInfo, function(i, o) {   
                            // if(o.ud_type == '1' || o.ud_type == '2' || o.ud_type == '3' || o.ud_type == '10'){
                            if(o.ud_type == '1' || o.ud_type == '2' || o.ud_type == '3'){
                                $('#imgsrc'+o.ud_type).attr('src',o.url);
                                $('#file'+o.ud_type).val(o.ud_url);
                            }
                        });
                    }
                    $('#countSubmit').val(parseInt($('#countSubmit').val())+1);
                }else{
                    $('.banner1').remove();
                }

                //身份证上传（正面、反面需验证，手持不需要验证）
                if(data.result.orderInfo.back_type.indexOf('2') >= 0){

                    if(data.result.daturmInfo.length>0){
                        var imghtml = '';
                        var num = 1;
                        var isShow = true;
                        var isShow1 = true;
                        $.each(data.result.daturmInfo, function(i, o) {
                            if(o.ud_type == '8'){
                                isShow = false;
                            }
                            if(o.ud_type == '9'){
                                isShow1 = false;
                            }
                            if(o.ud_type != '1' && o.ud_type != '2' && o.ud_type != '3' && o.ud_type != '10'){
                                imghtml += '<div class="idcardpic fl">';
                                imghtml += '<img class="picture portrait" id="imgsrc'+o.ud_type+'_'+num+'" src="'+o.url+'" alt="">';
                                imghtml += '<input class="upload1" type="file" name="file'+o.ud_type+'_'+num+'" accept="image/*" onchange="file_upload(this, \''+o.ud_type+'_'+num+'\')">';
                                imghtml += '<input type="hidden" id="file'+o.ud_type+'_'+num+'" class="userfiles" fileType="'+o.ud_type+'" value="'+o.ud_url+'">';
                                imghtml += '<div class="fixpic">'+o.ud_name+'</div>';
                                imghtml += '<div id="uploadpic'+o.ud_type+'_'+num+'"></div>';
                                imghtml += '</div>';
                                num += 1;
                            }
                        });
                        $('#yxzlTabInfo').html(imghtml);
                    }
                    if(data.result.workInfo.cus_flag == '3' && !isShow1){
                        var html = '';
                        html += '<div class="idcardpic fl" id="img9">';
                        html += '<img class="picture portrait" id="imgsrc9" src="/static/images/id1.png" alt="">';
                        html += '<input class="upload1" type="file" name="file9" accept="image/*" onchange="file_upload(this, \'9\')">';
                        html += '<input type="hidden" id="file9" class="userfiles" fileType="9" value="">';
                        html += '<div class="fixpic">学生证或校园卡</div>';
                        html += '<div id="uploadpic9"></div>';
                        html += '</div>';
                        $('#yxzlTabInfo').append(html);
                    }

                    //判断教育程度
                    if(data.result.userInfo.u_edu_degree < '40' && !isShow){
                        var html = '';
                        html += '<div class="idcardpic fl" id="img8">';
                        html += '<img class="picture portrait" id="imgsrc8" src="/static/images/id4.png" alt="">';
                        html += '<input class="upload1" type="file" name="file8" accept="image/*" onchange="file_upload(this, \'8\')">';
                        html += '<input type="hidden" id="file8" class="userfiles" fileType="8" value="">';
                        html += '<div class="fixpic">学信网截图</div>';
                        html += '<div id="uploadpic8"></div>';
                        html += '</div>';
                        $('#yxzlTabInfo').append(html);
                    }
                    $('#countSubmit').val(parseInt($('#countSubmit').val())+1);
                }else{
                    $('.banner2').remove();
                }
                
                if(data.result.orderInfo.back_type.indexOf('3') >= 0){
                    $('#msgInfo').html(common.formatTemplate(data.result.userInfo,$('#msgInfo').html(),true));
                    $('#xz_marriage').find('div[value="'+data.result.userInfo.u_marriage+'"]').addClass('selected');
                    $('#marriage').val(data.result.userInfo.u_marriage);
                    $('#education').find('option[value="'+data.result.userInfo.u_edu_degree+'"]').prop('selected',true);
                    setTimeout(function(){getCity(false,'','iprovince')}, 100);
                    setTimeout(function(){$('#iprovince').find('option[value="'+data.result.userInfo.u_province+'"]').prop('selected',true)}, 300);
                    setTimeout(function(){getCity('city',$('#iprovince').find('option:selected').attr('val'),'icity')}, 500);
                    setTimeout(function(){$('#icity').find('option[value="'+data.result.userInfo.u_city+'"]').prop('selected',true)}, 700);
                    setTimeout(function(){getCity('area',$('#icity').find('option:selected').attr('val'),'iarea')}, 900);
                    setTimeout(function(){$('#iarea').find('option[value="'+data.result.userInfo.u_area+'"]').prop('selected',true)}, 1100);
                    $('#countSubmit').val(parseInt($('#countSubmit').val())+1);
                }else{
                    $('.banner3').remove();
                }
                
                if(data.result.orderInfo.back_type.indexOf('4') >= 0){
                    if(data.result.workInfo.cus_flag == '1'){
                        data.result.workInfo.cus_flag = '自雇';
                        $(".banner4").css("min-height","18.25rem");
                        getTplHtml('workform',$('#workform'));
                        setTimeout(function(){$('#workInfo').html(common.formatTemplate(data.result.workInfo,$('#workInfo').html(),true))}, 200);
                        $('#biaos').val('1');
                        setTimeout(function(){
                            setTimeout(function(){getCity(false,'','wprovince')}, 100);
                            setTimeout(function(){$('#wprovince').find('option[value="'+data.result.workInfo.uw_province+'"]').prop('selected',true)}, 300);
                            setTimeout(function(){getCity('city',$('#wprovince').find('option:selected').attr('val'),'wcity')}, 500);
                            setTimeout(function(){$('#wcity').find('option[value="'+data.result.workInfo.uw_city+'"]').prop('selected',true)}, 700);
                            setTimeout(function(){getCity('area',$('#wcity').find('option:selected').attr('val'),'warea')}, 900);
                            setTimeout(function(){$('#warea').find('option[value="'+data.result.workInfo.uw_area+'"]').prop('selected',true)}, 1100);

                            var strArr = data.result.workInfo.uw_fld_name.split('->');
                            setTimeout(function(){$('#parent').find('option:contains("'+strArr[0]+'")').prop('selected',true)}, 50);
                            setTimeout(function(){clickOpt($('#parent').val())}, 100);
                            setTimeout(function(){$('#child1').find('option:contains("'+strArr[1]+'")').prop('selected',true)}, 150);
                            setTimeout(function(){clickOpt1(2,$('#child1').val(),list3[$('#child1').val()])}, 200);
                            setTimeout(function(){$('#child2').find('option:contains("'+strArr[2]+'")').prop('selected',true)}, 250);
                            setTimeout(function(){clickOpt1(3,$('#child2').val(),list4[$('#child2').val()])}, 300);
                            setTimeout(function(){$('#child3').find('option:contains("'+strArr[3]+'")').prop('selected',true)}, 350);
                        }, 200);
                    }else if(data.result.workInfo.cus_flag == '2'){
                        data.result.workInfo.cus_flag = '在职';
                        $('#workInfo').html(common.formatTemplate(data.result.workInfo,$('#workInfo').html(),true));
                        setTimeout(function(){
                            $('#biaos').val('2');
                            setTimeout(function(){getCity(false,'','wprovince')}, 100);
                            setTimeout(function(){$('#wprovince').find('option[value="'+data.result.workInfo.uw_province+'"]').prop('selected',true)}, 300);
                            setTimeout(function(){getCity('city',$('#wprovince').find('option:selected').attr('val'),'wcity')}, 500);
                            setTimeout(function(){$('#wcity').find('option[value="'+data.result.workInfo.uw_city+'"]').prop('selected',true)}, 700);
                            setTimeout(function(){getCity('area',$('#wcity').find('option:selected').attr('val'),'warea')}, 900);
                            setTimeout(function(){$('#warea').find('option[value="'+data.result.workInfo.uw_area+'"]').prop('selected',true)}, 1100);
                        }, 200);
                    }else if(data.result.workInfo.cus_flag == '3'){
                        $(".banner4").css("min-height","8.5rem");
                        data.result.workInfo.cus_flag = '学生';
                        getTplHtml('schoolform',$('#workform'));
                        setTimeout(function(){$('#workInfo').html(common.formatTemplate(data.result.workInfo,$('#workInfo').html(),true))}, 200);
                        setTimeout(function(){
                            laydate.render({elem: '#school_date',showBottom: false,min: '2010-1-1',max: 0,trigger: 'click'});
                            $('#com_years').find('option[value="'+data.result.workInfo.com_years+'"]').prop('selected',true);
                        }, 200);

                        $('#biaos').val('3');
                    }
                    $('#countSubmit').val(parseInt($('#countSubmit').val())+1);
                }else{
                    $('.banner4').remove();
                }
                
                if(data.result.orderInfo.back_type.indexOf('5') >= 0){
                    $('#contactInfo1').html(common.formatTemplate(data.result.contact[0],$('#contactInfo1').html(),true));
                    setTimeout(function(){$('#relation1').find('option[value="'+data.result.contact[0].ur_relation+'"]').prop('selected',true);}, 100);
                    $('#contactInfo2').html(common.formatTemplate(data.result.contact[1],$('#contactInfo2').html(),true));
                    setTimeout(function(){$('#relation2').find('option[value="'+data.result.contact[1].ur_relation+'"]').prop('selected',true);}, 100);
                    $('#countSubmit').val(parseInt($('#countSubmit').val())+1);
                }else{
                    $('.banner5').remove();
                }

                $('#changeorder').show();
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });  
}

//function file_upload(obj,n){
//    $('#file'+n).val('');
//    common.compress(obj, function(data){
//        $("#imgsrc"+n).attr("src",data[1]);
//        var sendData = data[1].replace('data:'+data[0]+';base64,', '');
//        var url = $('#upload_url').val();
//        var imgType = data[0].split('/')[1]=='jpeg'?'jpg':data[0].split('/')[1];
//        $("#uploadpic"+n).removeClass('complete').addClass('uploadpic').html('上传中').show();
//        $.post(url,{ext:imgType,content:sendData},function(datas){
//            $('#file'+n).val(datas.url);
//            if(datas.url){
//                $("#uploadpic"+n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
//            }
//        },'json');
//    });
//}

function file_upload(obj,n){
    var param = getRequest();
    //$('#file'+n).val('');
    common.compress(obj, function(data){
        var sendData = data[1].replace('data:'+data[0]+';base64,', '');
        var url = $('#upload_url').val();
        //获取图片后缀
        var imgType = data[0].split('/')[1]=='jpeg'?'jpg':data[0].split('/')[1];
        //获取图片大小
        var size = obj.files[0].size;
        //获取图片名称
        var name = obj.files[0].name;

        //获取身份证号和姓名
        var u_true_name= $('#name').val();
        var u_ident_no = $('#code').val();
        //ocr是否开启
        var ocr_back_open =  $('#ocr_back_open').val();

        if(n == '1' || n == '2' || n == '3'){
            if(ocr_back_open == 'on'){
                common.ajax({
                    data: {
                        interface:'users@checkIdCard',
                        fileContent:data[1],
                        fileType:n,
                        ext:imgType,
                        name:name,
                        content:sendData,
                        u_true_name:u_true_name,
                        u_ident_no:u_ident_no,
                        b_id:param['id'],
                        ocr_open_where:'back_open'
                    },
                    success: function (dat) {
                        if (dat.status == '2000') {
                            if(n == '1'){
                                if(dat.result.name){
                                    $('#u_true_name').val(dat.result.name);
                                    $('#u_ident_no').val(dat.result.code);
                                    $('#name').val(dat.result.name);
                                    $('#code').val(dat.result.code);
                                    $("#imgsrc" + n).attr("src", data[1]);
                                    $("#uploadpic" + n).removeClass('complete').addClass('uploadpic').html('上传中').show();
                                    $.post(url, {ext: imgType, content: sendData}, function (datas) {
                                        $('#file' + n).val(datas.url);
                                        if (datas.url) {
                                            $("#uploadpic" + n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
                                        }
                                    }, 'json');
                                }else{
                                    falert('请上传正确的身份证头像面');
                                }
                            }else if(n=='2'){
                                if (dat.result.issue) {
                                    $("#imgsrc" + n).attr("src", data[1]);
                                    $("#uploadpic" + n).removeClass('complete').addClass('uploadpic').html('上传中').show();
                                    $.post(url, {ext: imgType, content: sendData}, function (datas) {
                                        $('#file' + n).val(datas.url);
                                        if (datas.url) {
                                            $("#uploadpic" + n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
                                        }
                                    }, 'json');
                                } else {
                                    falert('请上传正确的身份证国徽面');
                                }
                            }else if(n=='3'){
                                if(dat.result.success){
                                    $("#imgsrc"+n).attr("src",data[1]);
                                    $("#uploadpic"+n).removeClass('complete').addClass('uploadpic').html('上传中').show();
                                    $.post(url,{ext:imgType,content:sendData},function(datas){
                                        $('#file'+n).val(datas.url);
                                        if(datas.url){
                                            $("#uploadpic"+n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
                                        }
                                    },'json');
                                }else{
                                    falert(dat.result.data.msg);
                                }
                            }
                        }else if(dat.status == '3000'){
                            $("#imgsrc"+n).attr("src",data[1]);
                            $("#uploadpic"+n).removeClass('complete').addClass('uploadpic').html('上传中').show();
                            $.post(url,{ext:imgType,content:sendData},function(datas){
                                $('#file'+n).val(datas.url);
                                if(datas.url){
                                    $("#uploadpic"+n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
                                }
                            },'json');
                        } else if (dat.status == '5000') {
                            falert(dat.msg);
                        }
                    }
                });
            }else{
                $("#imgsrc"+n).attr("src",data[1]);
                $("#uploadpic"+n).removeClass('complete').addClass('uploadpic').html('上传中').show();
                $.post(url,{ext:imgType,content:sendData},function(datas){
                    $('#file'+n).val(datas.url);
                    if(datas.url){
                        $("#uploadpic"+n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
                    }
                },'json');
            }
        }else{
            $("#imgsrc"+n).attr("src",data[1]);
            $("#uploadpic"+n).removeClass('complete').addClass('uploadpic').html('上传中').show();
            $.post(url,{ext:imgType,content:sendData},function(datas){
                $('#file'+n).val(datas.url);
                if(datas.url){
                    $("#uploadpic"+n).removeClass('uploadpic').addClass('complete').html('<img class="u1" src="/static/images/u1.png" alt="">').show();
                }
            },'json');
        }
    });
}

function getRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if(url.indexOf("?") != -1){
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }

    return theRequest;
}

// 提交信息
function submitMsg() {
    if($('#checkSubmit').val() != $('#countSubmit').val()){
        falert('请您先保存信息');
        return false;
    }
    var datas = {
        interface:'order@saveOrder', 
        b_id:common.get('id'),
        ocr_open_where:'back_open'
    };
    
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                falert('提交信息成功','/order/orderlist');
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}

function xzSelected(obj,id){
    $("#"+id+" .circle").removeClass("selected");
    $(obj).addClass("selected");
    if(id == 'xz_marriage'){
        var marriage = $('#'+id).find('.selected').attr('value');
        $('#marriage').val(marriage);
    }
}


/*图片放大*/
$(".img_mask").click(function(event){
    var src=$('#photo_example').val();
    var html = "<div id='fangda'><img src=''></div>";
    $("body").append(html);

    $("#fangda img").attr("src",src);

    $("#fangda").click(function(){
        $(this).remove();
    });
    event.stopPropagation();
});